package de.koller.worlders.gameplay.ability;

import de.koller.oceanFramework.tree.Child;
import de.koller.worlders.WSea;
import de.koller.worlders.engine.WInputGL;
import de.koller.worlders.gameplay.GameplayPlayer;
import org.lwjgl.input.Keyboard;

public class AbilityBar extends WSea {
	
	private GameplayPlayer gplayer;
	@Child private final AbilityBarV abilityBarV = new AbilityBarV();
	private int currentAbility = 1;

	@Override
	protected void init() {
		super.init();
		
		gplayer = wroot.gamePlayer;
	}
	
	@Override
	protected void update( int elapsedTime ) {
		super.update( elapsedTime );
		
		if( wroot.inventory.isVisible() )
			return;
		
		int lastAbility = currentAbility;
		
		WInputGL i = wroot.getInput();
		if( i.isKeyPressed( Keyboard.KEY_1 ) ) currentAbility = 1;
		else if( i.isKeyPressed( Keyboard.KEY_2 ) ) currentAbility = 2;
		else if( i.isKeyPressed( Keyboard.KEY_3 ) ) currentAbility = 3;
		else if( i.isKeyPressed( Keyboard.KEY_4 ) ) currentAbility = 4;
		else if( i.isKeyPressed( Keyboard.KEY_5 ) ) currentAbility = 5;
		
		if( lastAbility != currentAbility ) {
			Ability la = gplayer.playerAbility.getAbility( lastAbility - 1 );
			if( la != null )
				la.unactivated();
		}
		
		Ability c = gplayer.playerAbility.getAbility( currentAbility - 1 );
		if( c != null )
			c.activeUpdate();
	}
	
	public int getCurrentAbility() {
		return currentAbility;
	}
	
}
